module abox
import StdEnv, japi

import StdEnv, japi

/* This program takes action depending on the state of three check boxex. */

:: State = { frame::!Framer, 
             red::!TDev, green::!TDev, blue::!TDev}

Start world
  # (js, world) = begin_japi world
    (frm, js) = jnewFrame  (WH 400 300) "Colors" js
    msg= "Check one or more checkboxes"
    (lbl, js)= jnewLabel (XY 50 70) msg frm js
    lbl= jsetfont (Helvetia 20) lbl
    (r, js) = jnewCheckBox (XY 100 150) "Red"   frm js
    (g, js) = jnewCheckBox (XY 100 200) "Green" frm js
    (b, js) = jnewCheckBox (XY 100 250) "Blue"  frm js
    (frm, js) = jshow frm js
    (r, js) = jsetstate r 1 js
    (g, js) = jsetstate g 1 js
    frm= bg_color (red+green) frm
    (frm, js)= jsetcursor J_HAND frm js
    s= {frame= frm, red= r, green=g, blue= b}
    js= loop s js
  = end_japi js world
where
  loop :: !State !JapiState -> JapiState
  loop s js
     # (na, js) = jnextaction js
     | na== act s.frame= jquit js
     | na== act s.red || na== act s.green || na== act s.blue
          # (vRed, js)= jgetstate s.red js
          # c1= if vRed (255, 0, 0) (0, 0, 0)
          # (vGreen, js)= jgetstate s.green js
          # c2= if vGreen (0, 255, 0) (0, 0, 0)
          # (vBlue, js)= jgetstate s.blue js
          # c3= if vBlue (0,0,255) (0, 0, 0)
          # frm= bg_color (c1+c2+c3) s.frame
          = loop {s& frame= frm} js
     = loop s js


